package api

import (
	"gitee.com/DengAnbang/Computation/src/dbops"

	"gitee.com/DengAnbang/Computation/src/bean"
	"fmt"
)

/**
	* showdoc
	* @catalog socket文档/用户相关
	* @title 用户注册
	* @description 用户注册的接口
	* @method socket type=101
	* @url /pc/user/register
	* @param login_name 必选 string 登陆名
	* @param pwd 必选 string 密码
	* @param name 可选 string 用户昵称
	* @return {"code":0,"type":101,"message":"","debug_message":"","data":{"user_name":"用户7943","login_name":"testLoginName123","user_id":"10035"}}
	* @return_param type int 请求类型
	* @return_param name string 用户昵称
	* @remark 最后修改时间:2018.12.07 10.30
	* @number 99
	*/
func UserRegisterSocket(parameters map[string]string) (error) {
	loginName, pwd, name := fmt.Sprintf("%s", parameters["login_name"]), fmt.Sprintf("%s", parameters["pwd"]), fmt.Sprintf("%s", parameters["name"])
	user, err := dbops.UserRegister(loginName, pwd, name)
	if err != nil {
		return err
	}
	return bean.NewSucceedMessage(user)
}

/**
	* showdoc
	* @catalog socket文档/用户相关
	* @title 用户登陆
	* @description 用户登陆的接口
	* @method socket type=102
	* @url /pc/user/login
	* @param login_name 必选 string 登陆名
	* @param pwd 必选 string 密码
	* @return {"code":0,"type":102,"message":"","debug_message":"","data":{"user_name":"用户7943","login_name":"testLoginName123","user_id":"10035"}}
	* @return_param type int 请求类型
	* @return_param name string 用户昵称
	* @remark 最后修改时间:2018.12.07 10.30
	* @number 99
	*/
func UserLoginSocket(parameters map[string]string) (string, error) {
	loginName, pwd := fmt.Sprintf("%s", parameters["login_name"]), fmt.Sprintf("%s", parameters["pwd"])
	user, err := dbops.UserLogin(loginName, pwd)
	if err != nil {
		return "", err
	}
	return user.UserId, bean.NewSucceedMessage(user)

}
